#做一个学生点名系统，系统里支持：存入学生、更改学生、删除学生、点到学生姓名方法
#存入学生（姓名、年龄、家庭地址、手机号）： 存入成功后，提示xxx存入成功
#更改学生（姓名、年龄、家庭地址、手机号）：可以修改学生内容的任意一个字段
#删除学生：删除的学生将不在展示
#展示全部学生：可以看到全部的学生姓名
#学生姓名：随机抽取任意一个存在的学生信息，然后打印：到！。举例： 刘闯到！
#以上内容，需要连接数据库，每次的数据都需要增、删、改、查去做
#student表：name、age、address、phone_number

import pymysql
HOST="123.57.5.215"
USER="root"
PWD="Aa123456"
DATABASE="bobo"
pymysql_con = pymysql.connect(host = HOST,user = USER,password=PWD
                ,database=DATABASE,cursorclass=pymysql.cursors.DictCursor)

#cursor.execute('create table student(id int primary key auto_increment,name varchar(20))')


"""

self.HOST =HOST
self.USER = USER
self.pwd = pwd
self.DATABASE = DATABASE

class Student_System:
    list1 = []
    def write_studentinfo(self,name,age,address,phone_number):
        f = open('students.txt','r',encoding='utf-8')
        if name not in f.read():
            Student_System.list1.append({"学生姓名":name,"学生年龄":age,"学生地址":address,"学生手机号":phone_number})
            with open('students.txt','a',encoding='utf-8') as f:
                    f.write(f"学生姓名：{name}，学生年龄：{age}，学生地址：{address}，学生手机号为：{phone_number}")
                    print("存入成功！")
        else:
            pass
        f.close()
    def update_studentinfo(self,name = None,age= None,address= None,phone= None):
        if name is None:
            pass
        if age is None:
            pass
        if address is None:
            pass
        if phone is None:
            pass
        for i in Student_System.list1:
            if name == i['学生姓名']:
                i['学生姓名'] = name
                i['学生年龄'] = age
                i['学生地址'] = address
                i['学生手机号'] = phone
    def delete_student(self,name):
        for i in Student_System.list1:
            if name == i['学生姓名']:
                Student_System.list1.remove(i)
    def show_all(self):
        for i in Student_System.list1:
            print(f"学生姓名：{i['学生姓名']}，学生年龄：{i['学生年龄']}，学生地址：{i['学生地址']}，学生手机号为：{i['学生手机号']}")

    def dian(self):
        from random import choice
        values = [i['姓名'] for i in Student_System.list1]
        print(str(choice(values)) + "到！")
"""





